/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.guilayer.match;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

import it.unical.canonaco.rende.igpe.game.cbv.guilayer.components.OverallGUILayoutFactory;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.MatchManager;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author Massimo Canonaco
 *
 */
class RoundInformationPanel016 extends JPanel 
{

	/** */
	private JLabel timeLeft;
	
	/** */
	private JLabel currentSkillPoint;
	
	/** */
	private ImageIcon timerOn;
	
	/** */
	private ImageIcon timerOff;
	
//	/** */
//	private MatchPanel monitor;
	
	/** */
	private Image background;
	
	private int height;
	private int width;
	
	/** */
	public RoundInformationPanel016(MatchPanel container, Map<String, String> settings, Image background)
	{
		super();
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		OverallGUILayoutFactory gui = OverallGUILayoutFactory.getInstance();
		
//		monitor = container;
		timeLeft = new JLabel();
		currentSkillPoint = new JLabel();
		try {
			timerOn = new ImageIcon(ImageIO.read(new FileInputStream(settings.get("gameinformationpanel.timer.icon.on.path"))));
			timerOff = new ImageIcon(ImageIO.read(new FileInputStream(settings.get("gameinformationpanel.timer.icon.off.path"))));
			currentSkillPoint.setIcon(new ImageIcon(ImageIO.read(new FileInputStream(settings.get("gameinformationpanel.skillpoint.path")))));
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		width = container.getWidth();
		height = Integer.parseInt(settings.get("gameinformationpanel.size.height"));
//		Dimension dimension = new Dimension(container.getWidth(),Integer.parseInt(settings.get("gameinformationpanel.size.height")));
		Dimension dimension = new Dimension(width,height);
		Font font = gui.getHeaderFont().deriveFont(Float.parseFloat(settings.get("gameinformationpanel.text.size")));
		Color color = gui.getParsedColor(settings.get("gameinformationpanel.text.color"));
		timeLeft.setFont(font);
		timeLeft.setForeground(color);
		currentSkillPoint.setFont(font);
		currentSkillPoint.setForeground(color);
		setPreferredSize(dimension);
		setMaximumSize(dimension);
		setMinimumSize(dimension);
		setSize(dimension);
		timeLeft.setAlignmentX(LEFT_ALIGNMENT);
		add(timeLeft);
		add(Box.createHorizontalGlue());
		add(currentSkillPoint);
		this.background = background;
//		setBackground(Color.red);
	}
	
	/** */
	public void update(MatchManager manager)
	{
		timeLeft.setText(" "+Integer.toString((int) (manager.getCurrentTimeLeft()/1000))+" ");
		currentSkillPoint.setText(" "+Integer.toString((int) manager.getClientPlayer().getSkillPoints())+" ");
	}
	
	/** */
	public void changeTurn(boolean on)
	{
		if(on)
		{
			timeLeft.setIcon(timerOn);
		}
		else
		{
			timeLeft.setIcon(timerOff);
		}
	}
	
	@Override
	protected void paintComponent(Graphics g) 
	{
		super.paintComponent(g);
//		g.drawImage(background, width, height, null);
		g.drawImage(background,0,0, width, height, null);
	}
}
